/*
 * IkaAnim.cpp
 */

#include"IkaAnim.h"
#include"define.h"

using namespace atomic;
using namespace std;

namespace atomic {

//*********************************************************************
IkaAnim::IkaAnim() {
	Init();
}

//*********************************************************************
IkaAnim::IkaAnim(const IkaAnim & copy) {
	Init();
	myName = copy.myName;
	myDelay = copy.myDelay;
	isLooped = copy.isLooped;
	myFrames = copy.myFrames;
}

//*********************************************************************
IkaAnim::IkaAnim(string name, vector<IkaGraphic> & frames, float delay,
		bool looped) {
	Init();
	myName = name;
	myDelay = delay;
	isLooped = looped;
	myFrames = frames;
}

//*********************************************************************
IkaAnim::IkaAnim(string name, string frameName, float delay, bool looped) {
	Init();
	myName = name;
	myDelay = delay;
	isLooped = looped;
	AddFrame(frameName);
}

//*********************************************************************
IkaAnim::~IkaAnim() {
}

//*********************************************************************
void IkaAnim::Init() {
	myName = "anim";
	myDelay = 0.2f;
	isLooped = false;
	vector<IkaGraphic> myFrames(0);
}

//*********************************************************************
bool IkaAnim::Looped() const {
	return isLooped;
}

//*********************************************************************
float IkaAnim::Delay() const {
	return myDelay;
}

//*********************************************************************
vector<IkaGraphic>& IkaAnim::Frames(){
	return myFrames;
}

//*********************************************************************
string IkaAnim::Name() const{
	return myName;
}

//*********************************************************************
void IkaAnim::SetLooped(bool looped) {
	this->isLooped = looped;
}

//*********************************************************************
void IkaAnim::SetDelay(float delay) {
	this->myDelay = delay;
}

//*********************************************************************
bool IkaAnim::SetFrame(const IkaGraphic &frames, unsigned int index) {
	if (index < myFrames.size()) {
		try {
			myFrames[index] = frames;
			return true;
		} catch (int e) {
			printf("SetFrame failed!");
			return false;
		}
	} else {
		printf("SetFrame failed!: maxFrame");
		return false;
	}
}

//*********************************************************************
IkaAnim& IkaAnim::operator =(const IkaAnim & anim) {
	this->myName = anim.myName;
	this->myDelay = anim.myDelay;
	this->isLooped = anim.isLooped;
	this->myFrames = anim.myFrames;
	return *this;
}

//*********************************************************************
IkaGraphic & IkaAnim::operator [](unsigned int index) {
	return myFrames[index];
}

//*********************************************************************
IkaGraphic & IkaAnim::GetFrame(unsigned int index) {
	return myFrames[index];
}

//*********************************************************************
void IkaAnim::AddFrame(string name) {
	// creation of a frame
	IkaGraphic frame;
	frame.LoadFile(name.c_str());
	// try to set
	myFrames.push_back(frame);
	printf("Frame Added \n");
}

//*********************************************************************
void IkaAnim::SetName(string name) {
	this->myName = name;
}

//*********************************************************************
void IkaAnim::Clear() {
	myFrames.clear();
}
//*********************************************************************
}
